package com.ymatou.query.trading.api.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.trading.api.parameter.GetProductNumOfOrdersBean;
import com.ymatou.query.trading.api.service.GetProductNumOfOrdersCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取当前买家已购买的某个具体商品的数量（暂用于码头app） FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetProductNumOfOrders {

	private static GetProductNumOfOrdersBean getproductnumofordersbean;
	private static GetProductNumOfOrdersCall getproductnumoforderscall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取当前买家已购买的某个具体商品的数量（暂用于码头app）");
	}

	@Before
	public void caseUp() {

		getproductnumofordersbean = new GetProductNumOfOrdersBean();
		getproductnumoforderscall = new GetProductNumOfOrdersCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductnumoforderscall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductNumOfOrders_001() {
		Logger.start(true,"获取当前买家已购买的某个具体商品的数量（暂用于码头app）成功");
		try {
			// 创建订单
			Map map = new OrderCallService().appSaveOrder();		
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");
			String productId = (String) map.get("productId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);		
			// 参数
			getproductnumofordersbean.setBuyerId(userId);
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(17);
			getproductnumofordersbean.setOrderStatusList(list);
			getproductnumofordersbean.setProductId(productId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			getproductnumofordersbean.setStartTime(StartTime);
			// 发送请求
			getproductnumoforderscall.setData(getproductnumofordersbean);
			getproductnumoforderscall.callService();
			Logger.comment("getproductnumoforderscall send:" + getproductnumoforderscall.getEntityString());
			Logger.comment("getproductnumoforderscall response:" + getproductnumoforderscall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getproductnumoforderscall.getCode(), "验证Code");
			// Logger.verifyEquals(ErrorCode.SUCCESSMSG,
			// getproductnumoforderscall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}